﻿using Delonix_Regia_Hotel_Management_System.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Delonix_Regia_Hotel_Management_System
{
    public partial class UpdateStaffPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["user"] == null)
                {
                    Response.Redirect("LoginPage.aspx");
                }
            }
        }

        protected void btnLogout_Click(object sender, ImageClickEventArgs e)
        {
            Session["user"] = null;
            Response.Redirect("LoginPage.aspx");
        }

        protected void btnReport_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("ReportPage.aspx");
        }

        protected void btnStaff_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("StaffMainPage.aspx");
        }

        protected void btnRates_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("RatesPage.aspx");
        }

        protected void btnBooking_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("RoomAvailabilityPage.aspx");
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("QueryPage.aspx");
        }

        protected void btnCheckOut_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CheckOutPage.aspx");
        }

        protected void btnCheckIn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CheckInPage.aspx");
        }

        protected void btnAdmin_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("AdminMainPage.aspx");
        }

        protected void btnLogo_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("WelcomePage.aspx");
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            HotelUser u = DBManager.GetUserByName(tbxSearch.Text);
            lblUsername1.Text = u.Username;
            tbxPassword.Text = u.Password;
            tbxName.Text = u.Name;
            tbxDob.Text = u.Date_of_birth;
            tbxBankNum.Text = u.Bank_account_number;
            tbxHomeAdd.Text = u.Home_address;
            tbxTelNum.Text = u.Tel_num;
            lblRank.Text = u.Rank;
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string username = lblUsername1.Text;
            string password = tbxPassword.Text;
            string name = tbxName.Text;
            string dob = tbxDob.Text;
            string bankno = tbxBankNum.Text;
            string homeadd = tbxHomeAdd.Text;
            string telnum = tbxTelNum.Text;
            string rank = lblRank.Text;

            HotelUser u = new HotelUser(username, password, name, dob, bankno, homeadd, telnum, rank);

            int rowsupdated = DBManager.updateStaff(u);

            if (rowsupdated > 0)
            {
                lblStatus.Text = "Update successful!";
            }
            else
            {
                lblStatus.Text = "Update unsuccessful!";
            }

            tbxBankNum.Text = "";
            tbxDob.Text = "";
            tbxHomeAdd.Text = "";
            tbxName.Text = "";
            tbxPassword.Text = "";
            tbxTelNum.Text = "";
            lblRank.Text = "";
            lblUsername1.Text = "";

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("StaffMainPage.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            tbxBankNum.Text = "";
            tbxDob.Text = "";
            tbxHomeAdd.Text = "";
            tbxName.Text = "";
            tbxPassword.Text = "";
            tbxTelNum.Text = "";
        }
    }
}